#include "Frame.h"
#include <stdio.h>


//default constructor
Frame::Frame()
{
}

//overloaded constructor
Frame::Frame(int who, int dest, bool isData, char msg[])
{
    sender = who;
    destinationer = dest;
    if(isData)
    {
        frameType = DATA_FRAME;
    }
    else
    {
        frameType = ACK_FRAME;
    }
    sprintf(message, "%s", msg);
}

int Frame::getSender()
{
    return sender;
}

int Frame::getDestinationer()
{
    return destinationer;
}

int Frame::getFrameType()
{
    return frameType;
}

char* Frame::getMessage()
{
    return message;
}

void Frame::setSender(int who)
{
    sender = who;
}

void Frame::setDestinationer(int dest)
{
    destinationer = dest;
}

void Frame::setFrameType(int fType)
{
    frameType = fType;
}

void Frame::setMessage(char msg[])
{
    sprintf(message, "%s", msg);
}

//creates a NULL frame, which consists of a -1 for both
//sender and receiver
Frame Frame::getNullFrame()
{
    char msg[10];
    sprintf(msg, "%d", NACK);
    
    return Frame(-1, -1, false, msg);
}

//determines if the Frame received matches what is 
//qualified as a NULL frame, return true, else return false
bool Frame::isNullFrame(Frame toTest)
{
    Frame nullFrame = getNullFrame();
    
    if(
        toTest.getSender() == nullFrame.getSender()
        && toTest.getDestinationer() == nullFrame.getDestinationer()
        && toTest.getFrameType() == nullFrame.getFrameType()
        && toTest.getMessage() == nullFrame.getMessage()
      )
    {
        return true;
    }
    
    return false;
}
